﻿namespace Okazuki.MVVM.PrismSupport.FSharp.Test
{
    using System;
    using System.Text;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.ComponentModel.DataAnnotations;

    [TestClass]
    public class FsValidatableViewModelBaseTest
    {
        class TestViewModel : FsValidatableViewModelBase
        {
            private string name;

            [Required(ErrorMessage = "名前は必須です")]
            public string Name
            {
                get { return this.name; }
                set
                {
                    this.set(ref name, value, "Name");
                }
            }
        }

        private TestViewModel target;

        [TestInitialize]
        public void SetUp()
        {
            this.target = new TestViewModel();
        }

        [TestCleanup]
        public void TearDown()
        {
            this.target = null;
        }

        [TestMethod]
        public void TestValidateProperty()
        {
            Assert.IsFalse(this.target.HasErrors);
            this.target.Name = string.Empty;
            Assert.IsTrue(this.target.HasErrors);
            Assert.AreEqual("名前は必須です", this.target["Name"]);
        }
    }
}
